home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 October / EnigmA AMIGA RUN 31 (1998)(G.R. Edizioni)(IT)[!][issue 1998-10].iso / earkit / chat / amarquee / examples / sysmessage.rexx < prev   
OS/2 REXX Batch file  |  1998-09-22  |  3KB  |  91 lines

  1. /*************************************************
  2.  
  3.    sysmessage.rexx
  4.  
  5.    Author: Jeremy Friesner (jaf@chem.ucsd.edu)
  6.    
  7.    An ARexx script that sends a system message to
  8.    all clients logged in to the local AMarqueed
  9.    server.
  10.  
  11.    Usage:  rx sysmessage.rexx hostnames lognames message
  12.    
  13.    (hostnames) should be a regular expression denoting
  14.    the hostnames of the client or clients to be messaged.
  15.    (e.g. sdcc8.ucsd.edu or #?.edu)
  16.    
  17.    (lognames) should be a regular expression denoting
  18.    the lognames of the AMarquee client or clients to
  19.    be messaged (e.g. #?Netris or QAmiTrack).
  20.    
  21.    (message) Should be the message you want to send.
  22.    
  23.    Example:  rx sysmessage.rexx #? #? The system is shutting down!
  24.  
  25.    Note that you must have given localhost 
  26.    AMARQUEED_SENDSYSMESSAGE privilege in order for
  27.    this script to work.
  28.  
  29. ***************************************************/
  30.  
  31. parse arg hostnames lognames message 
  32.  
  33. if ((serverName == '?')|(length(hostnames) = 0)|(length(lognames)=0)) then do
  34.   say "Usage: rx sysmessage.rexx <hostnames> <logNames> <message>"
  35.   exit
  36.   end
  37.   
  38. serverName   = 'localhost'  /* hardcoded for now */
  39. portNum = 2957
  40. logName = 'sysmessage.rexx'
  41.  
  42. if (length(lognames) = 0) then lognames = '#?'
  43. if (length(message) = 0) then message = 'This is a system message.'
  44.  
  45. message = strip(message) /* Remove extra spaces */
  46.  
  47. /* We need to trap all the different ways the script could exit,
  48.    so that we can be sure any allocated QSessions or QMessages are
  49.    freed properly */
  50. signal on error
  51. signal on syntax
  52. signal on halt
  53. signal on break_c
  54.  
  55. /* Used to track allocated QSession */
  56. session = 0
  57.  
  58. /* Note the offset MUST be -204, and not -30 like in many other
  59.    libraries!  Note also that we require amarquee.library v46 or higher */
  60. check = addlib('amarquee.library', 0, -204, 46)
  61.  
  62. say "Connecting to server " || serverName || " on port " || portNum || " as " || logName
  63. session = QNewSession(serverName, portNum, logName)
  64. if (session > 0) then 
  65. do
  66.   messagereceivers = "/" || hostnames || "/" || lognames
  67.   say "Sending System Message to: " || messagereceivers
  68.   
  69.   call QRequestPrivilegesOp(session, QPRIV_SENDSYSMESSAGES)  
  70.  
  71.   /* Note that this won't work if the server doesn't give us
  72.      the privilege; this script doesn't check to see if the
  73.      privilege was actually granted, but rather assumes that it
  74.      was. */
  75.   call QSysMessageOp(session,messagereceivers,message)
  76.   
  77.   /* And off it goes... */
  78.   call QGo(session)
  79. end
  80.  
  81. /* Our error handling/cleanup routine starts here */
  82. ERROR:
  83. SYNTAX:
  84. HALT:
  85. BREAK_C:
  86.   say "Cleaning up..."
  87.   if (session > 0) then do
  88.     call QFreeSession(session)
  89.     end
  90.   exit
  91.